<?php


namespace App\Notifications\Wechat;


use App\Internals\UserInternal;

class OrderNeedPay extends Notification
{
    public function notify($userId, $tradeNo, $name, $actualPrice, $createdAt, $courseLevels)
    {
        $templateId = '29A_jLghyEyT0NeO7U5DwuUlz6nQ9eImXnakPik1k6U';
        $socialAccount = UserInternal::getSocialAccount($userId);
        $url = config('app.base_url') . '/?#/user/order';

        $tmp = [];
        foreach($courseLevels as $level) {
            $tmp[] = 'Level ' . $level . '课程';
        }
        $nameArr = explode('-', $name);
        $name =  trim($nameArr[1]) . ' - ' . implode('、', $tmp);

        $data = [
            'first' => $socialAccount['nickname'] . " 家长您好，你有一笔订单未付款，请在30分钟内支付。如有疑问，可拨打客服电话：4008558297\n",
            'keyword1' => [$name, '#FF6F6F'],
            'keyword2' => ['¥' . $actualPrice, '#FF6F6F'],
            'keyword3' => ['未支付', '#FF6F6F'],
            'keyword4' => [$createdAt, '#FF6F6F'],
            'keyword5' => [$tradeNo . "\n", '#FF6F6F'],
            'remark' => ['点击完成支付环节，也可点击下方了解订单详情！', '#FF6F6F'],
        ];
        $this->send($socialAccount['openId'], $templateId, $url, $data);
    }
}
